package org.wheel.plugins.starter.jdbc.pool.util;

import cn.hutool.core.util.XmlUtil;
import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class CustomXmlUtil {
    public static Document readXML(File file) throws Exception {
        // 创建 JDK DocumentBuilderFactory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        // 配置解析器
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        // 创建 DocumentBuilder
        DocumentBuilder builder = factory.newDocumentBuilder();
        // 解析 XML 文件
        return builder.parse(file);
//        // 使用 Hutool 的 XmlUtil 读取 XML 文件
//        return XmlUtil.readXML(file);
    }
}
